#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
typedef pair<int, int> PII;
PII arr[N];

int main() {
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i].first >> arr[i].second;
        //cout << arr[i][0]<<" "<<arr[i][1]<<endl;
    }
    sort(arr, arr + n);
    int r = arr[0].second;
    // for(int i = 0 ; i< n; i++) 
    // {
    //    // cin >> arr[i][0] >> arr[i][1];
    //     cout << arr[i].first<<" "<<arr[i].second<<endl;
    // }
    for (int i = 1; i < n; i++)
    {
        if (arr[i].first < r)
        {
            r = min(arr[i].second, r);
        }
        else
        {
            ans++;
            r = arr[i].second;
        }
    }
    cout << ans;





    return 0;
}